import { defineStore } from 'pinia'
import { reactive, ref } from 'vue'
import API from "@renderer/api";


const { musicHallApi } = API
export const useDjListStore = defineStore('djListStore', () => {
    const djList = ref([] as any[])
    const djDetails = reactive({} as {
        id: number,
        name: string,
        coverImgUrl: string,
        description: string,
        creator: {
            nickname: string,
            avatarUrl: string
        }
    })
    const getDjDetails = async (rid: number) => {
        let res = await musicHallApi.getDjDetailApi(rid)
        if (res.code == 200) {
            Object.assign(djDetails, {
                name: res.data.name,
                description: res.data.desc,
                id: res.data.id,
                coverImgUrl: res.data.picUrl,
                creator: {
                    nickname: res.data.dj.nickname,
                    avatarUrl: res.data.dj.avatarUrl
                }
            })
        }
    }
    const getDjList = async (rid: number) => {
        let res = await musicHallApi.getDjProgramApi(rid)
        if (res.code == 200) {
            djList.value = res.programs.map((item: any) => {
                return {
                    ...item.mainSong,
                    al: {
                        picUrl: djDetails.coverImgUrl,
                        name: djDetails.name,
                        id: djDetails.id
                    },
                    dt: item.duration,
                }
            })
        }
    }

    return {
        djList,
        djDetails,
        getDjDetails,
        getDjList
    }
})